<!-- 话题详情最热评论 -->
<template>
	<view class="content">
		<view class="haveReply" v-if='list.length'>
			<view class="replayItem" v-for='(item,index) in list' :key='index'>
				<avatar class="icon" :src="item.headPortrait"></avatar>
				<view class="rightBox">
					<view class="nicknameBox">
						<view class="left">
							<text>{{item.nickName}}</text>
							<view class="author" v-if="item.memberId == memberId">作者</view>
						</view>
						<view class="right" @click.stop="praise(item,index)">
							<view class="pic">
								<image v-if="!Boolean(item.greatFlag)" src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/topicIcon/good.png"></image>
								<image v-else src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/topicIcon/good_act.png"></image>
							</view>
							<text>{{item.greatNum}}</text>
						</view>
					</view>
					<view class="speak">{{item.content}}</view>
					<view class="ip_box">
						<view class="time">{{item.createTime}}</view>
						<view v-if="item.lastLoginAddress">{{'IP属地: '+item.lastLoginAddress}}</view>
						<text @click="$emit('reply',item)">回复</text>
					</view>
					<!-- 回复 -->
					<view class="itemReply" v-if="item.commentNum">
						<view class="item1" v-for='(cell,idx) in item.replys' :key='idx' v-if="cell.isShow">
							<avatar class="icon" :src="cell.headPortrait"></avatar>
							<view class="right">
								<view class="box1">
									<view class="name">{{cell.nickName}}</view>
									<view class="author" v-if="cell.memberId ==memberId">作者</view>
								</view>
								<view class="box2">{{cell.content}}</view>
								<view class="box3">
									<view class="time">{{cell.createTime}}</view>
									<view v-if="cell.lastLoginAddress">{{'IP属地: '+cell.lastLoginAddress}}</view>
								</view>
							</view>
						</view>
					</view>
					<view class="packOran" v-if="item.commentNum">
						<view class="boe" v-if="item.openSize <= item.commentNum" @click="showReply(item,index)">
							<view class="line"></view>
							<view>展开更多回复</view>
							<image src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/topicIcon/_img4.png"></image>
						</view>
						<view class="boe" v-else @click="hideReply(item,index)">
							<view class="line"></view>
							<text>收起</text>
							<image src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/topicIcon/_img6.png"></image>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="load" />
		</view>

	</view>
</template>

<script>
	import {
		childComment,
		addGreat
	} from '@/apis/apis.js'
	import avatar from '@/components/avatar.vue'
	export default {
		name: "talkList",
		components: {
			avatar
		},
		props: {
			list: {
				type: Array,
				default: []
			},
			show: {
				type: Boolean,
				default: false
			},
			replyIndex: Number,
			replyValue: String,
			load: {
				type: String,
				default: 'loadmore'
			},
			memberId: {
				type: Number,
				default: ""
			}
		},
		data() {
			return {
				goodimgList: [{
						url: 'https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/topicIcon/_img1.png'
					},
					{
						url: 'https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/zan1.png'
					}
				],
				//展示更多回复
				shower: false
			}
		},
		methods: {
			// 赞
			praise(val, index) {
				console.log(val)
				addGreat({
					objectId: val.id,
					objectType: 2
				}).then(res => {
					console.log(res)
					if (res.code == 200) {
						this.list[index].greatFlag = !this.list[index].greatFlag
						if (Boolean(this.list[index].greatFlag)) {
							this.list[index].greatNum++
						} else {
							this.list[index].greatNum--
						}
					}
				})
			},
			// 展开回复
			showReply(item, index) {
				this.$emit('showReply', item, index)
			},
			hideReply(item, index) {
				this.$emit('closeReply', item, index)
			},
		},

	}
</script>

<style scoped lang="scss">
	.content {
		padding-top: 30rpx;

		.replyPopup {
			width: 100%;
			height: 136rpx;
			display: flex;
			justify-content: center;

			.inputbg {
				width: 80.8%;
				height: 70rpx;
				background: #F5F5F5;
				border-radius: 14rpx;
				margin-right: 22rpx;
				display: flex;
				align-items: center;
				padding: 0 32rpx;

				.inpt {
					width: 100%;
					font-size: 26rpx;
					font-family: Source Han Sans CN;
					color: #9F9F9F;
				}

				.placeholder {
					font-size: 26rpx;
					font-family: Source Han Sans CN;
					color: #9F9F9F;
				}
			}

			&>text {
				font-size: 26rpx;
				font-family: Source Han Sans CN;
				color: #194FC9;
			}
		}

		.haveReply {
			width: 100%;

			.replayItem {
				display: flex;

				.icon {
					width: 72rpx;
					height: 72rpx;
					border-radius: 50%;
					overflow: hidden;
				}

				.rightBox {
					width: 90%;
					padding: 0 0 0 16rpx;

					// border: 1rpx solid black;
					.nicknameBox {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.left {
							font-size: 26rpx;
							font-family: Source Han Sans CN;
							color: #747474;
							display: flex;
							align-items: center;

							.author {
								margin-left: 14rpx;
								padding: 0 10rpx;
								line-height: 36rpx;
								text-align: center;
								font-size: 20rpx;
								border-radius: 20rpx;
								border: 1rpx solid #194FC9;
								color: #369CFE;
							}
						}

						.right {
							display: flex;
							align-items: center;
							font-size: 24rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #999999;

							.pic {
								width: 32rpx;
								height: 32rpx;
								margin-right: 10rpx;

								image {
									display: block;
									width: 100%;
									height: 100%;
								}
							}
						}
					}

					.speak {
						padding: 6rpx 80rpx 20rpx 0;
						font-size: 30rpx;
						font-family: Source Han Sans CN;
						color: #2B2B2B;
					}

					.ip_box {
						display: flex;
						align-items: center;
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #B4B4B4;
						margin-bottom: 40rpx;

						.time {
							padding: 0 18rpx 0 0;
						}

						&>text {
							font-family: Source Han Sans CN;
							color: #878787;
							padding: 0 0 0 72rpx;
						}
					}

					.itemReply {
						width: 100%;

						// border: 1rpx solid blue;
						.item1 {
							display: flex;

							.icon {
								width: 40rpx;
								height: 40rpx;
								border-radius: 50%;

							}

							.right {
								width: 100%;
								padding: 0 20rpx 0 16rpx;

								.box1 {
									display: flex;
									font-size: 26rpx;
									font-family: Source Han Sans CN;
									color: #747474;

									.author {
										margin-left: 14rpx;
										padding: 0 10rpx;
										line-height: 36rpx;
										text-align: center;
										font-size: 20rpx;
										border-radius: 20rpx;
										border: 1rpx solid #194FC9;
										color: #369CFE;
									}
								}

								.box2 {
									font-size: 15px;
									font-family: Source Han Sans CN;
									color: #2B2B2B;
									padding: 14rpx 80rpx 24rpx 0;
								}

								.box3 {
									display: flex;
									align-items: center;
									font-family: PingFang SC;
									font-size: 13px;
									font-weight: 500;
									color: #B4B4B4;
									margin-bottom: 40rpx;

									.time {
										padding: 0 18rpx 0 0;
									}
								}
							}
						}
					}

					.packOran {
						font-size: 28rpx;
						font-family: Source Han Sans CN;
						font-weight: 500;
						color: #878787;

						.boe {
							display: flex;
							align-items: center;
							margin-bottom: 50rpx;

							.line {
								width: 44rpx;
								height: 2rpx;
								background: #E4E4E4;
							}

							&>image {
								width: 24rpx;
								height: 14rpx;
								margin-left: 8rpx;
							}
						}
					}
				}
			}
		}

	}
</style>
